package com.wc.算法基础课.A第一讲基础算法.区间合并.区间合并;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/2/29 20:50
 * @description https://www.acwing.com/problem/content/805/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static int[][] segs = new int[N][2];
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            segs[i][0] = sc.nextInt();
            segs[i][1] = sc.nextInt();
        }
        Arrays.sort(segs, 1, n + 1, (o1, o2) -> {
            if (o1[0] == o2[0]) {
                return o1[1] - o2[1];
            }
            return o1[0] - o2[0];
        });
        int st = Integer.MIN_VALUE, ed = Integer.MIN_VALUE;
        int res = 0;
        for (int i = 1; i <= n; i++) {
            int[] seg = segs[i];
            if (seg[0] <= ed) {
                ed = Math.max(seg[1], ed);
            } else {
                st = seg[0];
                ed = seg[1];
                res++;
            }
        }
        System.out.println(res);
    }


//    static int N = 100010;
//    static Seg[] segs = new Seg[N];
//    static int n;
//    static int st, ed;
//
//    public static void main(String[] args) {
//        n = sc.nextInt();
//        for (int i = 1; i <= n; i++) {
//            st = sc.nextInt();
//            ed = sc.nextInt();
//            Seg seg = new Seg(st, ed);
//            segs[i] = seg;
//        }
//        Arrays.sort(segs, 1, n + 1);
//        int ed = Integer.MIN_VALUE;
//        int res = 0;
//        for (int i = 1; i <= n; i++) {
//            if (ed < segs[i].st) {
//                res++;
//            }
//            ed = Math.max(segs[i].ed, ed);
//        }
//        out.println(res);
//        out.flush();
//    }
//
//    static class Seg implements Comparable<Seg> {
//        int st, ed;
//
//        Seg(int st, int ed) {
//            this.st = st;
//            this.ed = ed;
//        }
//
//        @Override
//        public int compareTo(Seg o) {
//            if (st == o.st) {
//                return ed - o.ed;
//            }
//            return st - o.st;
//        }
//    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

